<!--
 * @Descripttion: 查看部门成员
 * @Author: caijj
 * @Date: 2021-02-26 13:50:29
 * @LastEditors: caijj
 * @LastEditTime: 2021-02-26 14:43:15
-->
<template>
  <div class="content">
    <table-pagination
      :max-height="500"
      :columns="columns"
      :data="tableData"
      :total="total"
      :current-page="current"
      @handlePaginationChange="onPaginationChange"
    />
  </div>
</template>

<script>
import TablePagination from '@/components/common/TablePagination';
import { getDepartmentUser } from '@/api/partRoleApi';
import Columns from '../config';

export default {
  components: {
    TablePagination
  },
  props: {
    department: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      columns: Columns.employeeColumns,
      tableData: [],
      loading: false,
      total: 0,
      current: 1
    };
  },
  created() {
    this.onPaginationChange();
  },
  methods: {
    /* 分页查询 */
    onPaginationChange({ current = 1, size = 10 } = {}) {
      this.loading = true;
      const params = {
        department: this.department,
        pageNo: current,
        pageSize: size
      };
      getDepartmentUser(params).then(({ current, data, resultCode }) => {
        if (resultCode === '0000') {
          this.current = current;
          this.total = data.length;
          this.tableData = data.map(({ domain, name, phone, department }) => ({
            domain,
            name,
            phone,
            fullName: department.fullName
          }));
          this.loading = false;
        }
      }).catch(err => {
        console.log(err);
        this.loading = false;
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.content {
  // height: 460px;
  margin-bottom: 50px;
}
</style>
